package org.NooLab.nativebrowser.app.config;

import java.io.Serializable;


import org.NooLab.nativebrowser.components.NativeBrowserCommons;
import org.NooLab.utilities.files.DFutils;




public class NNBAppProperties 
									implements 
												ITexxAppPropertiesIntf,
												Serializable{

	public static final int _MAX_PAGES_SearchEngine = 100;
	
	transient NativeBrowserCommons appCommons;
	
	
	
	String ownBinPath="";
	String ownAppPath="";
	String configFilename="";

	
	private boolean earlyPreprocessing=true;

	private boolean allowForTransparency = true;

	private boolean alwaysOnTop = false;



	
	
	static int maxNumberOfSearchEnginePages = _MAX_PAGES_SearchEngine;

	
	// ========================================================================
	public NNBAppProperties(){
		
	}
	// ========================================================================
	
	public static ITexxAppPropertiesIntf getInstance(String basePath) {
		NNBAppProperties props = new NNBAppProperties();
		
		// destatify the string variables...
		CareForPathVariables cp = new CareForPathVariables(props, basePath);
		String filename = props.getConfigFilename() ;
		
		if (DFutils.fileExists(filename)==false){
			// System.out.println("properties file not found, proceeding with default settings...");
			return props;
		}
		

		return props;
	}

	
	@Override
	public String getOwnBinPath() {
		return ownBinPath;
	}



	// ------------------------------------------------------------------------
	public boolean isEarlyPreprocessing() {
		return earlyPreprocessing;
	}

	public void setEarlyPreprocessing(boolean earlyPreprocessing) {
		this.earlyPreprocessing = earlyPreprocessing;
	}


	public static int getMaxNumberOfSearchEnginePages() {
		return maxNumberOfSearchEnginePages;
	}
	public int getMaxNumberOfSearchenginePages() {
		return maxNumberOfSearchEnginePages;
	}

	public void setMaxNumberOfSearchEnginePages(int maxNumberOfSearchEnginePages) {
		this.maxNumberOfSearchEnginePages = maxNumberOfSearchEnginePages;
	}


	public boolean isAllowForTransparency() {
		return allowForTransparency;
	}


	public void setAllowForTransparency(boolean allowForTransparency) {
		this.allowForTransparency = allowForTransparency;
	}



	@Override
	public String getConfigFilename() {
		return configFilename;
	}


	public void setConfigFilename(String configFilename) {
		this.configFilename = configFilename;
	}



	public void setOwnBinPath(String ownBinPath) {
		this.ownBinPath = ownBinPath;
	}

	@Override
	public String getOwnAppPath() {
		return ownAppPath;
	}


	public void setOwnAppPath(String ownAppPath) {
		this.ownAppPath = ownAppPath;
	}


	@Override
	public void setCommonsReference(NativeBrowserCommons commons) {
		
		appCommons = commons;
	}

	
	
}



class CareForPathVariables{
	
	public CareForPathVariables(NNBAppProperties props, String basePath){

		if (basePath.contains("/dev/java/")){
			basePath = "D:/data/iTexx/bin/" ;
		}
		
		props.ownBinPath = basePath;
		props.ownAppPath = DFutils.createPath( DFutils.getParentDir(basePath), "app/nnb/config");
		// load properties from file

		props.configFilename = DFutils.createPath(props.ownAppPath, "nnb.cfg");

	}
}
